home *** CD-ROM | disk | FTP | other *** search
- #include <types.h>
- #include <quickdraw.h>
- #include <windows.h>
- #include <controls.h>
- #include <menus.h>
- #include <dialogs.h>
- #include <resources.h>
- #include <OSevents.h>
- #include <script.h>
- #include <fonts.h>
- #include <Events.h>
- #include <textedit.h>
- #include <OSUtils.h>
- #include <Traps.h>
-
- #define NIL ((void *) 0l)
-
- pascal void Debugger() extern 0xa9ff;
-
- void DoDialog();
- Boolean DialogExists();
- void PositionDialog();
- void SetItemValue();
- int GetItemValue();
- void HiliteItem();
- Handle GetItemHandle();
-
- main()
- {
- FlushEvents (everyEvent - diskMask, 0 );
- InitGraf (&qd.thePort);
- InitFonts ();
- InitWindows ();
- InitMenus ();
- TEInit ();
- InitDialogs (nil); /* no restart proc */
- InitCursor ();
-
- DoDialog();
- }
-
- void DoDialog()
- {
- short id;
- DialogPtr dlog;
-
- if(!DialogExists(256))
- {
- SysBeep(3);
- return;
- }
-
- dlog = GetNewDialog(256, NULL, (WindowPtr) -1);
-
- PositionDialog(dlog);
-
- SetItemValue(dlog, 2, 1);
-
- ShowWindow(dlog);
-
- do
- {
- ModalDialog(NULL, &id);
- if(id == 2)
- {
- SetItemValue(dlog, 2, !GetItemValue(dlog, 2));
- HiliteItem(dlog, 3, GetItemValue(dlog, 2) ? 0 : 255);
- }
- } while(id > ok);
-
- DisposDialog(dlog);
- }
-
- Handle GetItemHandle(dlog, item, type, rect)
- DialogPtr dlog;
- int item;
- short *type;
- Rect *rect;
- {
- Rect r;
- short t;
- Handle hand;
-
- if(!rect)
- rect = &r;
- if(!type)
- type = &t;
- GetDItem(dlog, item, type, &hand, rect);
-
- return hand;
- }
-
- GetItemValue(dlog, item)
- DialogPtr dlog;
- int item;
- {
- return GetCtlValue(GetItemHandle(dlog, item, NIL, NIL));
- }
-
- void SetItemValue(dlog, item, value)
- DialogPtr dlog;
- int item;
- {
- SetCtlValue(GetItemHandle(dlog, item, NIL, NIL), value);
- }
-
- void HiliteItem(dlog, item, value)
- DialogPtr dlog;
- int item;
- int value;
- {
- Rect rect;
- short type;
- Handle hand;
-
- hand = GetItemHandle(dlog, item, &type, &rect);
-
- type &= ~itemDisable;
- if((type & ~3) == ctrlItem)
- HiliteControl(hand, value);
- }
-
- void PositionDialog(dptr)
- DialogPtr dptr;
- {
- GrafPtr wPort;
- int hPos, vPos;
- Rect wRect, dRect;
-
- GetWMgrPort(&wPort);
- wRect = wPort->portRect;
- wRect.top += GetMBarHeight();
- dRect = dptr->portRect;
- hPos = (wRect.left + wRect.right + dRect.left - dRect.right) / 2;
- if(hPos < (wRect.left + 3))
- hPos = wRect.left + 3;
- vPos = (2 * wRect.top + wRect.bottom + dRect.top - dRect.bottom) / 3;
- if(vPos < (wRect.top + 3))
- vPos = wRect.top + 3;
- MoveWindow(dptr, hPos, vPos, false);
- }
-
- Boolean DialogExists(id)
- short id;
- {
- DialogTHndl hand;
- if(!(hand = (DialogTHndl) GetResource('DLOG', id)))
- return 0 != 0;
- return GetResource('DITL', (*hand)->itemsID) != 0;
- }
-